<?php
use_helper('I18N');
?>
<script type="text/javascript" language="javascript">
    var usdToMyr = "";
    $(function() {
        $("#paymentType").change(function() {
            /*if ($(this).val() == "BANK") {
                $(".bankDisplay").show();
            } else {
                $(".bankDisplay").hide();
            }*/
            $("#cbo_mt4Amount").change();
        }).trigger("change");

        $("#btnSubmit").click(function(){
            $("#withdrawForm").submit();
        });

        $("#cbo_mt4Amount").change(function() {
            var mt4Final = $("#cbo_mt4Amount").val() - 50;
            var handlingCharge = $("#cbo_mt4Amount").val() * 0.95;

            if (parseFloat(handlingCharge) < mt4Final)
                mt4Final = handlingCharge;

            $("#mt4Final").autoNumericSet(mt4Final);
        }).trigger("change");

        $("#withdrawForm").validate({
            messages : {
                transactionPassword: {
                    remote: "Security Password is not valid."
                }
            },
            rules : {
                /*"transactionPassword" : {
                    required : true
                    , remote: "/member/verifyTransactionPassword"
                }*/
            },
            submitHandler: function(form) {
                if ($("#mt4Id").val() == "") {
                    alert("mt4 status is pending.");
                    return false;
                }
                waiting();

                form.submit();
            }
        });
    }); // end function
</script>
<div class="row">
    <div class="col-md-12">
        <h2 class="page-title"><?php echo __("Withdrawal"); ?>
            <small></small>
        </h2>
    </div>
</div>
<div class="row">
    <div class="col-md-7">
        <section class="widget">
            <header>
                <h4>
                    <i class="icon-ok-sign"></i>
                    <?php echo __("Withdrawal"); ?>
                    <small></small>
                </h4>
            </header>
            <div class="body">
                <form class="form-horizontal label-left" method="post"
                      action="/member/mt4Withdrawal"
                      data-validate="parsley"
                      id="withdrawForm" name="withdrawForm">
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Withdrawal")?>
                        </legend>
                        <?php include_component('component', 'alert', array('param' => $sf_user->getAttribute(Globals::SESSION_DISTID, 0))) ?>
                        <div class="row">
                            <div class="col-sm-8">

                                <div class="control-group">
                                    <label class="control-label" for="mt4Id">
                                    <?php echo __("MT4 ID")?>
                                    </label>

                                    <div class="controls form-group">
                                        <select name="mt4Id" id="mt4Id">
                                            <?php
                                                if (count($distMt4DBs) >= 1) {
                                                    foreach ($distMt4DBs as $distMt4DB) {
                                                        echo "<option value='".$distMt4DB->getMt4UserName()."'>".$distMt4DB->getMt4UserName()."</option>";
                                                    }
                                                } else {
                                                    echo "<option value=''>--</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group" style="display: none;">
                                    <label class="control-label" for="mt4Id">
                                    <?php echo __("Payment Type")?>
                                    </label>

                                    <div class="controls form-group">
                                        <select name="paymentType" id="paymentType">
                                            <option value='VISA'>VISA Cash Card</option>
                                            <option value='BANK'>Local Bank Transfer</option>
                                        </select>
                                        <input name="myrCurrency" id="myrCurrency" disabled="disabled" value=""/>
                                        <input name="handlingFee" id="handlingFee" disabled="disabled" value=""/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="cbo_mt4Amount">
                                    <?php echo __("Withdrawal Amount")?>
                                    </label>

                                    <div class="controls form-group">
                                        <select name="mt4Amount" id="cbo_mt4Amount">
                                            <?php
                                                //if ($distributorDB->getMt4UserName() != null) {
                                                for ($i = 100; $i <= 10000; $i = $i + 100) {
                                                    echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                                                }
                                                for ($i = 20000; $i <= 50000; $i = $i + 10000) {
                                                    echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                                                }
                                                //}
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="mt4Final">
                                    <?php echo __("After handling fee")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input name="mt4Final" id="mt4Final" readonly="readonly" value="" class="form-control" />
                                    </div>
                                </div>
                                <div class="control-group" style="display: none;">
                                    <label class="control-label" for="grandAmount">
                                    <?php echo __("Grand Amount")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input name="grandAmount" id="grandAmount" disabled="disabled" value="" class="form-control" />
                                        <span class="currencyCode"></span>
                                    </div>
                                </div>

                                <!--<div class="control-group">
                                    <label class="control-label" for="transactionPassword">
                                    <?php /*echo __("Security Password")*/?>
                                    </label>

                                    <div class="controls form-group">
                                        <input name="transactionPassword" type="password" id="transactionPassword" class="form-control"/>
                                    </div>
                                </div>-->
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <legend class="section">
                                    <?php echo __('NOTE :'); ?>
                                </legend>
<!--                                <ol style="background-color: #F9F2F4; color: #C7254E; list-style: decimal; padding-left: 20px;" class="help-block">-->
                                <ol class="help-block" style="list-style: decimal; padding-left: 20px;">
                                    <li><?php echo __('Minimum withdrawal amount : USD 100'); ?></li>
                                    <li><?php echo __('Handling fee USD50 or 5% whichever is higher'); ?></li>
                                    <li><?php echo __('Processing time : 5 working days'); ?></li>
                                </ol>
                            </div>
                        </div>
                    </fieldset>
                    <div class="form-actions">
                        <button type="button" id="btnSubmit" class="btn btn-danger"><?php echo __("Submit");?></button>
                        <a href="/member/summary" class="btn btn-default"><?php echo __("Cancel");?></a>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>

<script type="text/javascript" language="javascript">
var datagrid = null;
$(function() {
    datagrid = $("#datagrid").r9jasonDataTable({
        // online1DataTable extra params
        "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
        "extraParam" : function(aoData) { // pass extra params to server
        },
        "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
            reassignDatagridEventAttr();
        },

        // datatables params
        "bLengthChange": true,
        "bFilter": false,
        "bProcessing": true,
        "bServerSide": true,
        "bAutoWidth": false,
        "sAjaxSource": "/finance/mt4WithdrawalList",
        "sPaginationType": "full_numbers",
        "aaSorting": [
            [2,'desc']
        ],
        "aoColumns": [
            { "sName" : "dist_id", "bVisible" : false,  "bSortable": true},
            { "sName" : "currency_code", "bVisible" : false,  "bSortable": true},
            { "sName" : "created_on",  "bSortable": true},
            { "sName" : "mt4_user_name",  "bSortable": true},
            { "sName" : "amount_requested",  "bSortable": true},
            { "sName" : "handling_fee",  "bSortable": false},
            { "sName" : "grand_amount",  "bSortable": false},
            { "sName" : "payment_type",  "bVisible": false},
            { "sName" : "status_code",  "bSortable": true},
            { "sName" : "remarks",  "bSortable": true}
        ]
    });
}); // end function

function reassignDatagridEventAttr() {
}
</script>

<div class="row">
<!--    <div class="col-md-10 col-md-offset-1">-->
    <div class="col-md-12">
        <section class="widget">
            <header>
                <h4>
                    <i class="icon-file-alt"></i>
                    <?php echo __('Withdrawal Status') ?>
                </h4>
            </header>
            <div class="body">
                <div>
                    <table class="table table-striped" id="datagrid" border="0" width="100%">
                        <thead>
                        <tr>
                            <th></th>
                            <th><?php echo __('Currency Code') ?></th>
                            <th><?php echo __('Date') ?></th>
                            <th><?php echo __('MT4 ID') ?></th>
                            <th><?php echo __('Amount Requested (USD)') ?></th>
                            <th><?php echo __('Bank Charges (USD)') ?></th>
                            <th><?php echo __('Grand Amount (USD)') ?></th>
                            <th><?php echo __('Payment Type') ?></th>
                            <th><?php echo __('Status') ?></th>
                            <th><?php echo __('Remarks') ?></th>
                        </tr>
                        </thead>
                    </table>
                    <br>
                    <br>
                </div>
            </div>
        </section>
    </div>
</div>